﻿// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.Composition.ReflectionModel;
using System.Globalization;
using System.Reflection;
using Microsoft.Internal;
using Microsoft.Internal.Collections;

namespace System.ComponentModel.Composition.AttributedModel
{
    internal class AttributedMemberImportDefinition : AttributedImportDefinition
    {
        private readonly ReflectionWritableMember _member;

        public AttributedMemberImportDefinition(MemberInfo member)
            : this(member.ToReflectionWritableMember(), member)
        {
        }

        private AttributedMemberImportDefinition(ReflectionWritableMember member, ICustomAttributeProvider attributeProvider)
            : base(member.ReturnType, attributeProvider)
        {
            this._member = member;
        }

        public override bool IsPrerequisite
        {
            get { return false; }
        }

        public MemberInfo Member
        {
            get { return _member.UnderlyingMember; }
        }

        public override string ToString()
        {
            return string.Format(
                CultureInfo.InvariantCulture,
                "ContractName={0},DeclaringType={1},MemberName={2}",
                this.ContractName,
                this._member.DeclaringType.FullName,
                this._member.Name);
        }

        public override ImportingItem ToImportingItem()
        {
            return new ImportingMember(this, this._member);
        }
    }
}
